package com.seata.demo.order.feign;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(name = "storage-service")
//@LocalTCC
public interface TccStorageFeignClient {

    @TwoPhaseBusinessAction(name = "storageTccAction", commitMethod = "commit", rollbackMethod = "rollback")
    @PostMapping("/storage/tcc/tryDeduct")
    boolean tryDeduct(
            @BusinessActionContextParameter(paramName = "commodityCode") @RequestParam("commodityCode") String commodityCode,
            @BusinessActionContextParameter(paramName = "count") @RequestParam("count") Integer count);

    @PostMapping("/storage/tcc/commit")
    boolean commit(BusinessActionContext context);

    @PostMapping("/storage/tcc/rollback")
    boolean rollback(BusinessActionContext context);
}
